package com.study.samsung.Dao;

import com.study.samsung.Entity.Commoditycolor;
import com.study.samsung.Entity.Commoditymemory;
import com.study.samsung.Utils.RowMapper;
import com.study.samsung.Utils.SQLHelper;

import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.List;

public class CommoditycolorDao {
    SQLHelper helper = new SQLHelper();

    public List<Commoditycolor> selectAll(){
        String sql = "select * from commoditycolor";
        return helper.query(sql,new CommoditycolorRowMapper());
    }

    public List<Commoditymemory> selectmemoryAll(){
        String sql = "select * from commoditymemory";
        return helper.query(sql,new CommoditymemoryRowMapper());
    }

    class CommoditycolorRowMapper implements RowMapper<Commoditycolor>{

        @Override
        public Commoditycolor map(ResultSet rs) throws SQLException {
            return new Commoditycolor(rs.getInt("yid"),
                    rs.getString("yname"));
        }
    }

    class CommoditymemoryRowMapper implements RowMapper<Commoditymemory>{

        @Override
        public Commoditymemory map(ResultSet rs) throws SQLException {
            return new Commoditymemory(rs.getInt("nid"),
                    rs.getString("nname"));
        }
    }
}
